﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace Karasoft.Web.UI.Weather
{
    public class IslamicFinderPrayerService
    {

        public static Prayer GetPrayerTime(string country, string city)
        {
            string surl = @"http://www.islamicfinder.org/prayer_service.php?country={0}&city={1}&state=00&zipcode=&latitude=25.3783&longitude=49.5867&timezone=3&HanfiShafi=1&pmethod=4&fajrTwilight1=10&fajrTwilight2=10&ishaTwilight=10&ishaInterval=30&dhuhrInterval=1&maghribInterval=1&dayLight=0&simpleFormat=xml";
            string Seviceurl = string.Format(surl, country, city);
            string s = GeneralHelper.GetXml(Seviceurl);

            XDocument ddddd = XDocument.Parse(s);
            var doc = ddddd.Element("prayer");
            DateTime dd = DateTime.Parse(doc.Element("date").Value, System.Globalization.CultureInfo.GetCultureInfo("en-US"));
            Prayer p = new Prayer();
            
              p.  Date = dd;
                p.Fajr = new DateTime(dd.Year, dd.Month, dd.Day, doc.Element("fajr").Value.Split(':')[0].ToInt(), doc.Element("fajr").Value.Split(':')[1].ToInt(), 0);
                p.Sunrise = new DateTime(dd.Year, dd.Month, dd.Day, doc.Element("sunrise").Value.Split(':')[0].ToInt(), doc.Element("sunrise").Value.Split(':')[1].ToInt(), 0);
                p.Dhuhr = new DateTime(dd.Year, dd.Month, dd.Day, doc.Element("dhuhr").Value.Split(':')[0].ToInt(), doc.Element("dhuhr").Value.Split(':')[1].ToInt(), 0);
                p.Asr = new DateTime(dd.Year, dd.Month, dd.Day, doc.Element("asr").Value.Split(':')[0].ToInt(), doc.Element("asr").Value.Split(':')[1].ToInt(), 0);
                p.Maghrib = new DateTime(dd.Year, dd.Month, dd.Day, doc.Element("maghrib").Value.Split(':')[0].ToInt(), doc.Element("maghrib").Value.Split(':')[1].ToInt(), 0);
                p.Isha = new DateTime(dd.Year, dd.Month, dd.Day, doc.Element("isha").Value.Split(':')[0].ToInt(), doc.Element("isha").Value.Split(':')[1].ToInt(), 0);
                p.City = city;
                p.Country = country;
                p.Hijri = Karasoft.Web.UI.Utility.DateUtility.ConvertToHijriDate(dd);
            return p;

        }
    }


   public class Prayer
   {
       public DateTime Fajr { get; set; }
       public DateTime Sunrise { get; set; }
       public DateTime Dhuhr { get; set; }
       public DateTime Asr { get; set; }
       public DateTime Maghrib { get; set; }
       public DateTime Isha { get; set; }
       public DateTime Date { get; set; }
       public string Hijri { get; set; }
       public string City { get; set; }
       public string Country { get; set; }
   }
}
